<template>
  <div>
        <div>
            <el-row class="">
              <el-col class="">
                <el-form ref="form"  label-position='right' size="small" :inline="true" label-width="110px">
                  <el-col :span="5" >
                      <el-form-item label="" prop="name" size='small'  style="margin:12px 5px;">
                          <el-input prefix-icon="el-icon-search" placeholder="请输入登录名" v-model="listQuery.condition.user_loginName.value" clearable></el-input>
                      </el-form-item>
                  </el-col>
                  <el-col :span="5" >
                      <el-form-item label="" prop="name" size='small'  style="margin:12px 5px;">
                          <el-input prefix-icon="el-icon-search" placeholder="请输入用户名" v-model="listQuery.condition.user_name.value" clearable></el-input>
                      </el-form-item>
                  </el-col>
                  <el-col :span="5">
                      <el-form-item label="" prop="isInner" size='small' style="margin:12px 0px;">
                          <el-select placeholder="是否兼职机构" v-model="listQuery.condition.pt.value" clearable>
                              <el-option v-for="item in  ptOptions" :key="item.key" :label="item.display_name" :value="item.key">
                              </el-option>
                          </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="6" style="padding-left:5px;margin-top:12px;float:left;width:200px" algin="left">
                      <el-button size="small" style="height:30px;padding-top:0px;line-height:30px;" type="success" icon="el-icon-edit" @click="editTree('find')">查 询</el-button>
                      <el-button size="small" style="height:30px;padding-top:0px;line-height:30px;" type="danger" icon="el-icon-edit" @click="handleReset()">重 置</el-button>
                     </el-col>
                  </el-form>
                </el-col>

            </el-row>
            <el-table
              :key='tableKey'
              :data="userData"
              size="small"
              height="335px"
              highlight-current-row
              style="width: 100%;border:#eeeeee;">
            <el-table-column align="center" label="序号" min-width="50px" type="index">
              <template slot-scope="scope">
              <span>{{scope.$index + (serialNumber - 1) * listQuery.rowBounds.limit + 1}}</span>
              </template>
            </el-table-column>
            </el-table-column>
              <el-table-column
                prop="user_loginName"
                label="登录名"
                 align="center"
                width="120">
              </el-table-column>
              <el-table-column
                prop="user_name"
                label="用户名称"
                 align="center"
                width="120">
              </el-table-column>
              <el-table-column
                prop="user_orgName"
                label="用户机构"
                 align="center"
                width="180">
              </el-table-column>
              <el-table-column
                prop="user_orderNo"
                label="用户编码" align="center" >
              </el-table-column>
              <el-table-column
                label="是否兼职" align="center"  >
                    <template slot-scope="scope">
                        <span>{{scope.row.pt | ptFilter}}</span>
                    </template>
              </el-table-column>
              <el-table-column
                label="兼职部门" align="center" >
                  <template slot-scope="scope"  v-if="scope.row.pt == 1">
                      <span>{{scope.row.pt_orgName}}</span>
                  </template>
              </el-table-column>
              <el-table-column
                label="操作" align="center" >
                  <template slot-scope="scope">
                    <el-button @click="handleDelete(scope.row,'delete')" type="text" size="small">删除</el-button>
                  </template>
              </el-table-column>
            </el-table>
          <div class="pagination-container" style="margin-top: 1px;">
            <el-pagination background @size-change="handleSizeChange"
                           @current-change="handleCurrentChange"
                           :current-page="listQuery.page" :page-sizes="[10,20,30, 50]"
                           :page-size="listQuery.rowBounds.limit" layout="total, sizes, prev, pager, next, jumper"
                           :total="total">
            </el-pagination>
          </div>

          <el-row :gutter="5">
            <el-col style="text-align: center; border-top:1px solid #e6e6e6; padding-top:20px; margin-top:10px;">
              <!--<el-button class="filter-item" type="primary" @click="saveData">保 存</el-button>-->
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-button size="small" class="filter-item" type="primary" @click="closeSelf"  style="float:right;">关 闭</el-button>
              <el-button size="small" class="filter-item" type="primary" icon="el-icon-circle-plus-outline" @click="handleCreate" style="float:right; margin-right: 20px">按组织机构添加人员</el-button>
              <el-button size="small" class="filter-item" type="primary" icon="el-icon-circle-plus-outline" @click="handleCreateBatch" style="float:right; margin-right: 20px">添加人员</el-button>
            </el-col>
          </el-row>
        </div>

    <el-dialog
      title="按组织机构添加人员"
      :visible.sync="dialogVisible"
      append-to-body
      top="1vh"
      width="85%">
      <el-row>
        <el-col :span="8">
          <el-tree ref='tree'
                   :data="treeData"
                   v-loading="loading"
                   style="height: 400px; overflow: scroll"
                   :props="defaultProps"
                   :expand-on-click-node='false'
                   @node-click="handleNodeClick"
                   node-key="id"
                   :highlight-current='true'
                   :default-expand-all='true'>
                      <span class="custom-tree-node" slot-scope="{ node, data }">
                        <span v-if="data.other.Status == 0" style="display: inline-block;width: 100%;">{{ data.name }}</span>
                        <span v-if="data.other.Status == 1" style="display: inline-block;width: 100%;color:red">{{ data.name }}(禁用)</span>
                        <div style="display: inline-block;" class="treeNone">
                        </div>
                       </span>
                   </el-tree>
        </el-col>
        <el-col :span="16">
          <div style="margin-top:15px;">
            <div class="select-container">
              <el-row class="">
                <el-col :span="24" class="">
                  <el-form ref="form" label-width="100px" label-position='right' size="small" :inline="true">
                    <el-col :span="4" >
                      <el-form-item label="" style="margin:12px 5px;">
                        <el-input placeholder="登录名称" prefix-icon="el-icon-search" v-model="listQueryDemo.condition.user_loginName.value" clearable>
                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="4" >
                      <el-form-item label="" style="margin:12px 3px;">
                        <el-input placeholder="用户名称" prefix-icon="el-icon-search" v-model="listQueryDemo.condition.user_name.value" clearable>
                        </el-input>
                      </el-form-item>
                    </el-col>
                  <el-col :span="6">
                      <el-form-item label="" prop="isInner" size='small' style="margin:12px 3px;">
                          <el-select placeholder="是否兼职机构" v-model="listQueryDemo.condition.pt.value" clearable>
                              <el-option v-for="item in  ptOptions" :key="item.key" :label="item.display_name" :value="item.key">
                              </el-option>
                          </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="10" style="padding-left:3px;margin-top:12px;float:right;margin-right:0">
                      <el-button size="small" style="height:30px;padding-top:0px;line-height:30px;" type="success" icon="el-icon-edit" @click="selectUserByOrgId()">查 询</el-button>
                      <el-button size="small" style="height:30px;padding-top:0px;line-height:30px;" type="danger" icon="el-icon-circle-close-outline" @click="handleResetOrg()">重 置</el-button>
                    </el-col>
                  </el-form>
                </el-col>
              </el-row>
            </div>
          </div>
          <el-table
            :data="userDataDemo"
            size="small"
            @select-all="selectionOrgChange"
            @select="selectionOrgChange"
             @selection-change="selectionValOrgChange"
            height="330px"
            style="width: 100%;overflow: auto;border:#eeeeee">
            <el-table-column
              type="selection"
              width="30" align="center" >
            </el-table-column>
            <el-table-column type="index" label="序号" width="50" align="center">
              <template slot-scope="scope">
              <span>{{scope.$index + (serialNumberOrg - 1) * listQueryDemo.rowBounds.limit + 1}}</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="user_loginName"
              label="登录名"
              width="120" align="center" >
            </el-table-column>
            <el-table-column
              prop="user_name"
              label="用户名称"
              width="120" align="center" >
            </el-table-column>
            <el-table-column
              prop="user_orgName"
              label="用户机构" width="180" align="center" >
            </el-table-column>
            <el-table-column
              label="是否兼职" align="center" width="90">
                <template slot-scope="scope">
                    <span>{{scope.row.pt | ptFilter}}</span>
                </template>
            </el-table-column>
            <el-table-column
              label="操作"
              align="center" >
              <template slot-scope="scope">
                <el-button @click="handleClick(scope.row)" type="text" size="small">添加</el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="pagination-container">
            <el-pagination background @size-change="handleSizeChangeDemo"
                           @current-change="handleCurrentChangeDemo"
                           :page-sizes="[10,20,30, 50]"
                           :page-size="listQueryDemo.rowBounds.limit"
                           layout="total, sizes, prev, pager, next, jumper"
                           :total="totalDemo">
            </el-pagination>
          </div>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="insertOrgList('insert')" type="primary">保存</el-button>
        <el-button size="small" @click="dialogVisible = false" type="primary">关 闭</el-button>
      </span>
      </el-dialog>
      <el-dialog
        title="添加人员"
        :visible.sync="addDialogVisible"
        append-to-body
        top="1vh"
        width="70%">
        <el-row class="">
          <el-col class="">
            <el-form ref="form"  label-position='right' size="small" :inline="true" label-width="110px">
              <el-col :span="5" >
                  <el-form-item label="" prop="name" size='small'  style="margin:12px 5px;">
                      <el-input prefix-icon="el-icon-search" placeholder="请输入登录名" v-model="listQueryAll.condition.user_loginName.value" clearable></el-input>
                  </el-form-item>
              </el-col>
              <el-col :span="5" >
                  <el-form-item label="" prop="name" size='small'  style="margin:12px 5px;">
                      <el-input prefix-icon="el-icon-search" placeholder="请输入用户名" v-model="listQueryAll.condition.user_name.value" clearable></el-input>
                  </el-form-item>
              </el-col>
              <el-col :span="5">
                  <el-form-item label="" prop="isInner" size='small' style="margin:12px 0px;">
                      <el-select placeholder="是否兼职机构" v-model="listQueryAll.condition.pt.value" clearable>
                          <el-option v-for="item in  ptOptions" :key="item.key" :label="item.display_name" :value="item.key">
                          </el-option>
                      </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6" style="padding-left:5px;margin-top:12px;float:left;width:200px" algin="left">
                  <el-button size="small" style="height:30px;padding-top:0px;line-height:30px;" type="success" icon="el-icon-edit" @click="getList('find')">查 询</el-button>
                  <el-button size="small" style="height:30px;padding-top:0px;line-height:30px;" type="danger" icon="el-icon-edit" @click="handleResetAll()">重 置</el-button>
                 </el-col>
              </el-form>
            </el-col>

        </el-row>
        <el-row>
          <el-col :span="24">
            <el-table
              :data="allUserData"
              size="small"
              height="355px"
              @select="selectionChange"
              @select-all="selectionChange"
              @selection-change="selectionValChange"
              style="width: 100%;overflow: auto;border:#eeeeee">
              <el-table-column
                type="selection"
                width="120" align="center" >
              </el-table-column>
              <el-table-column type="index" label="序号" width="50">
                <template slot-scope="scope">
                <span>{{scope.$index + (serialNumberAll - 1) * listQueryAll.rowBounds.limit + 1}}</span>
                </template>
              </el-table-column>
              <el-table-column
                prop="user_loginName"
                label="登录名"
                width="120" align="center" >
              </el-table-column>
              <el-table-column
                prop="user_name"
                label="用户名称"
                width="150" align="center" >
              </el-table-column>
              <el-table-column
                prop="user_orgName"
                label="用户机构" align="center" >
              </el-table-column>
              <el-table-column
                label="是否兼职" align="center" >
                  <template slot-scope="scope">
                      <span>{{scope.row.pt | ptFilter}}</span>
                  </template>
              </el-table-column>
              <el-table-column
                label="兼职部门" align="center" >
                  <template slot-scope="scope" v-if="scope.row.pt == 1">
                      <span>{{scope.row.pt_orgName}}</span>
                  </template>
              </el-table-column>
            </el-table>
            <div class="pagination-container">
              <el-pagination background @size-change="handleSizeChangeBatch"
                             @current-change="handleCurrentChangeBatch"
                             :page-sizes="[10,20,30, 50]"
                             layout="total, sizes, prev, pager, next, jumper"
                             :page-size="listQueryAll.rowBounds.limit"
                             :total="allTotal">
              </el-pagination>
            </div>
          </el-col>
        </el-row>
        <span slot="footer" class="dialog-footer">
          <el-button size="small" @click="insertList('insert')" type="primary">保存</el-button>
          <el-button size="small" @click="addDialogVisible = false" type="primary">关 闭</el-button>
        </span>
      </el-dialog>
  </div>
</template>

<script>
import {
  batchInsertItemUser,
  userSelected,
  selectExistUser,
  SysOrgInfo,
  treeById,
  deleteHandle
} from '@/api/systemManage/roleManagementRoleEdit'
import {
  ptOptions,
  statusOptions,
  ptKeyValue
} from '@/utils/allOptions'
export default {
  name: 'editRoleUser',
  components: {},
  props: ['editJob'],
  data() {
    return {
      tableKey: 0,
      total: 0,
      treeData: [],
      loading: false,
      dialogVisible: false,
      addDialogVisible: false,
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      oldMenuIdArr: [],
      listQuery: {
        rowBounds: {
          offset: 0,
          limit: 10
        },
        condition: {
          pt: {
            property: 'pt',
            value: '0',
            type: 'EQ'
          },
          user_loginName: {
            property: 'user_loginName',
            value: '',
            type: 'LIKE'
          },
          user_name: {
            property: 'user_name',
            value: '',
            type: 'LIKE'
          }
        },
        fields: [
        ],
        sort: [{
          direction: 'ASC',
          property: 'user_orderNo'
        }]
      },
      listQueryDemo: {
        rowBounds: {
          offset: 0,
          limit: 10
        },
        condition: {
          pt: {
            property: 'pt',
            value: '0',
            type: 'EQ'
          },
          user_loginName: {
            property: 'user_loginName',
            value: '',
            type: 'LIKE'
          },
          user_name: {
            property: 'user_name',
            value: '',
            type: 'LIKE'
          },
          orgId: {
            property: 'orgId',
            value: '',
            type: 'EQ'
          }
        },
        fields: [
        ],
        sort: [{
          direction: 'ASC',
          property: 'user_orderNo'
        }]
      },
      listQueryAll: {
        rowBounds: {
          offset: 0,
          limit: 10
        },
        fields: [
        ],
        sort: [{
          direction: 'ASC',
          property: 'user_orderNo'
        }],
        condition: {
          pt: {
            property: 'pt',
            value: '0',
            type: 'EQ'
          },
          user_name:{
            property: 'user_name',
            value: '',
            type: 'LIKE'
          },
          user_loginName:{
            property: 'user_loginName',
            value: '',
            type: 'LIKE'
          }
        }
      },
      totalDemo: 0,
      form: '',
      userData: [],
      userDataDemo: [],
      allTotal: 0,
      allUserData: [],
      ptOptions,
      checkedUserIds: [],
      checkedUsers: [],
      checkedUserList: [],
      checkedOrgUserIds: [],
      checkedOrgUsers: [],
      checkedOrgUserList: [],
      checkedOrgData: [],
      checkedOffset: 0,
      multipleSelection:[],
      multipleOrgSelection:[],
      serialNumber: 1,
      serialNumberOrg: 1,
      serialNumberAll: 1,
      statusOptions
    }
  },
  created() {
    this.editTree()
  },
  filters: {
    ptFilter(target) {
      return ptKeyValue[target]
    }
  },
  methods: {
    handleDelete(row,flag) {
    this.$confirm('此操作将删除人员【' + row.user_name + '】, 是否继续?', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    })
      .then(() => {
      var rowDemo = [
        {
          userId: row.user_id,
          roleId: this.editJob.id,
          orgId: row.orgId
        }
      ]
      deleteHandle(rowDemo).then(response => {
        this.editTree(flag)
        this.$message({
          message: '删除成功',
          type: 'success'
        })
      })
     })
    },
    // 翻页器使用
    handleSizeChange(val) {
      this.listQuerypage = 1
      this.listQuery.rowBounds.limit = val
      this.listQuery.rowBounds.offset = this.listQuery.rowBounds.limit * (this.serialNumber - 1)
      this.editTree()
    },
    // 翻页器使用
    handleCurrentChange(val) {
      this.serialNumber = val
      this.listQuerypage = val
      this.listQuery.rowBounds.offset =
        this.listQuery.rowBounds.limit * (val - 1)
      this.editTree()
    },
    // 翻页器使用(按组织机构添加人员)
    handleSizeChangeDemo(val) {
      this.listQueryDemo.rowBounds.limit = val
      this.listQueryDemo.rowBounds.offset = this.listQueryDemo.rowBounds.limit * (this.serialNumberOrg - 1)
      this.listQueryDemo.isExist = 0
      this.selectUserByOrgId()
    },
    // 翻页器使用(按组织机构添加人员)
    handleCurrentChangeDemo(val) {
        this.serialNumberOrg = val
        this.listQueryDemo.rowBounds.offset =
        this.listQueryDemo.rowBounds.limit * (val - 1)
        this.listQueryDemo.isExist = 0
        this.selectUserByOrgId()
    },
    // 翻页器使用(添加人员)
    handleSizeChangeBatch(val) {
      this.listQueryAll.rowBounds.limit = val
      this.listQueryAll.isExist = 0
      this.listQueryAll.rowBounds.offset = this.listQueryAll.rowBounds.limit * (this.serialNumberAll - 1)
      this.listQueryAll.orgId = this.$store.getters.orgId
      userSelected(this.listQueryAll).then(response => {
        this.allUserData = response.data.data.records
        this.allTotal = response.data.data.count
      })
    },
    // 翻页器使用(添加人员)
    handleCurrentChangeBatch(val) {
        this.serialNumberAll = val
        this.listQueryAll.rowBounds.offset =
        this.listQueryAll.rowBounds.limit * (val - 1)
        this.listQueryAll.isExist = 0
        this.listQueryAll.orgId = this.$store.getters.orgId
        userSelected(this.listQueryAll).then(response => {
        this.allUserData = response.data.data.records
        this.allTotal = response.data.data.count
      })
    },
    handleClick(row) {
      var rowDemo = [
        {
          userId: row.user_id,
          roleId: this.editJob.id,
          orgId: row.orgId
        }
      ]
      var userRow = [];
      SysOrgInfo(rowDemo).then(response => {
        if ((this.listQueryDemo.rowBounds.offset == (this.totalDemo - 1)
        || this.userDataDemo.length == this.multipleOrgSelection.length)
         && this.listQueryDemo.rowBounds.offset >= this.listQueryDemo.rowBounds.limit) {
          if (this.serialNumberOrg * this.listQueryDemo.rowBounds.limit >= this.totalDemo) {
            this.listQueryDemo.rowBounds.offset -=this.listQueryDemo.rowBounds.limit
            this.serialNumberOrg -=1
          }
        }
        this.selectUserByOrgId()
        this.editTree()
        this.$message({
          message: '添加成功',
          type: 'success'
        })
      })
    },
    handleCreate() {
      this.dialogVisible = true
      treeById({ id: this.$store.getters.orgId }).then(response => {
        this.treeData = response.data.data
        if (this.$store.state.user.selectRoleOrgId) {
          this.$nextTick(() => {
            this.$refs.tree.setCurrentKey(this.$store.state.user.selectRoleOrgId) // treeBox 元素的ref   value 绑定的node-key
          })
          this.listQueryDemo.condition.orgId.value = this.$store.state.user.selectRoleOrgId
          this.listQueryDemo.roleId = this.editJob.id
          this.listQueryDemo.isExist = 0
          this.selectUserByOrgId()
         }
      })
    },
    handleCreateBatch() {
      this.addDialogVisible = true
      this.getList()
    },
    getList(flag) {
        if (flag ==='find') {
          this.checkedUsers=[];
          this.checkedUserIds=[];
          this.listQueryAll.rowBounds.offset = 0
          this.allTotal = 0
          this.serialNumberAll =1
        }
        this.listQueryAll.roleId = this.editJob.id
        this.listQueryAll.isExist = 0
        this.listQueryAll.orgId = this.$store.getters.orgId

        if (flag ==='insert') {
          if ((this.listQueryAll.rowBounds.offset == (this.allTotal - 1)
          || this.allUserData.length == this.multipleSelection.length)
           && this.listQueryAll.rowBounds.offset >= this.listQueryAll.rowBounds.limit) {
            if (this.serialNumberAll * this.listQueryAll.rowBounds.limit >= this.allTotal) {
              this.serialNumberAll -=1
              this.listQueryAll.rowBounds.offset -=this.listQueryAll.rowBounds.limit
            }
          }
        }
        userSelected(this.listQueryAll).then(response => {
          this.allUserData = response.data.data.records
          this.allTotal = response.data.data.count
        })
    },
    handleNodeClick(data) {
      this.checkedOrgUsers=[];
      this.checkedOrgUserIds=[];
      this.serialNumberOrg =1
      this.listQueryDemo.rowBounds.offset =0
      this.totalDemo =0
      this.listQueryDemo.condition.orgId.value = data.id
      this.$store.commit('SET_SELECTROLEORGID', data.id)
      this.listQueryDemo.roleId = this.editJob.id
      this.listQueryDemo.isExist = 0
      this.selectUserByOrgId()
    },
    editTree(flag) {
      this.loading = true
      this.listQuery.roleId = this.editJob.id
      this.listQuery.isExist = 1
      this.listQuery.orgId = this.$store.getters.orgId
      if (flag ==='find') {
        this.listQuery.rowBounds.offset = 0
        this.total = 0
        this.serialNumber =1
      }
      if (flag === 'delete') {
        if (this.listQuery.rowBounds.offset == (this.total - 1)
         && this.listQuery.rowBounds.offset >= this.listQuery.rowBounds.limit) {
          if (this.serialNumber * this.listQuery.rowBounds.limit >= this.total) {
            this.listQuery.rowBounds.offset -=this.listQuery.rowBounds.limit
            this.serialNumber -=1
          }
        }
      }
      userSelected(this.listQuery).then(response => {
        this.userData = response.data.data.records
        this.total = response.data.data.count
        this.loading = false
      })
    },
    saveData() {
      const insertArr = []
      const checkedKeys = this.$refs.tree.getCheckedKeys()
      for (const temp of checkedKeys) {
        const input = {}
        input.userId = this.editJob.rowId
        input.roleId = temp
        input.orgId = this.editJob.id
        insertArr.push(input)
      }
      batchInsertItemUser(insertArr).then(response => {
        this.$notify({
          title: '成功',
          message: '更新成功',
          type: 'success',
          duration: 2000
        })
        this.$emit('changeCloseDialog')
        // this.$router.push({ name: 'roleManagement' })
      })
    },
    closeSelf() {
      this.$emit('changeCloseDialog')
      // this.$router.push({ name: 'roleManagement' })
    },
   selectionChange(val,row) {
     this.checkedUsers=[];
     this.checkedUserIds=[];
     if(val){
       for(var i in val){
           var tempUserRoleOrg = {
             roleId: '',
             userId: '',
             orgId: ''
           }
          tempUserRoleOrg.roleId = this.editJob.id
          tempUserRoleOrg.userId = val[i].user_id
          tempUserRoleOrg.orgId = val[i].orgId
          this.checkedUsers.push(tempUserRoleOrg)
          this.checkedUserIds.push(val[i].user_id)
       }
     }
     this.checkedUserList = [];
     this.checkedUserList = val;
   },
   selectionValChange(val) {
    this.multipleSelection = val
   },
   selectionValOrgChange(val) {
    this.multipleOrgSelection = val
   },
   selectionOrgChange(val,row) {
       this.checkedOrgUsers=[];
       this.checkedOrgUserIds=[];
       if(val){
         for(var i in val){
             var tempUserRoleOrg = {
               roleId: '',
               userId: '',
               orgId: ''
             }
            tempUserRoleOrg.roleId = this.editJob.id
            tempUserRoleOrg.userId = val[i].user_id
            tempUserRoleOrg.orgId = val[i].orgId
            this.checkedOrgUsers.push(tempUserRoleOrg)
            this.checkedOrgUserIds.push(val[i].user_id)
         }
       }
       this.checkedOrgUserList = [];
       this.checkedOrgUserList = val;
   },
    insertList(flag) {
      if (this.checkedUsers.length > 0) {
        batchInsertItemUser(this.checkedUsers).then(response => {
          // 已选人员
          this.editTree()
          // 未选人员
          this.getList(flag)
          this.$message({
            message: '批量添加成功',
            type: 'success'
          })
        })
        this.checkedUsers = []
        this.checkedUserIds=[];
      } else {
          this.$message({
            message: '请选择人员',
            type: 'warning'
          })
      }
    },
     insertOrgList(flag) {
     if (this.checkedOrgUsers.length > 0) {
         batchInsertItemUser(this.checkedOrgUsers).then(response => {
          // 已选人员
          this.editTree()
          // 未选人员
          this.listQueryDemo.isExist = 0
          if (flag ==='insert') {
            if ((this.listQueryDemo.rowBounds.offset == (this.totalDemo - 1)
            || this.userDataDemo.length == this.multipleOrgSelection.length)
             && this.listQueryDemo.rowBounds.offset >= this.listQueryDemo.rowBounds.limit) {
             if (this.serialNumberOrg * this.listQueryDemo.rowBounds.limit >= this.totalDemo) {
                this.listQueryDemo.rowBounds.offset -=this.listQueryDemo.rowBounds.limit
                this.serialNumberOrg -=1
              }
            }
          }
          userSelected(this.listQueryDemo).then(response => {
            this.userDataDemo = response.data.data.records
            this.totalDemo = response.data.data.count
          })
          this.$message({
            message: '按机构批量添加成功',
            type: 'success'
          })
         })
          this.checkedOrgUsers=[];
          this.checkedOrgUserIds=[];
       } else {
          this.$message({
            message: '请选择人员',
            type: 'warning'
          })
       }
     },
     handleReset() {
       this.listQuery.condition.user_loginName.value = ''
       this.listQuery.condition.user_name.value = ''
       this.listQuery.condition.pt.value = '0'
       this.listQuery.rowBounds.offset = 0
       this.listQuery.rowBounds.limit = 10
       this.total = 0
       this.serialNumber = 1
       this.editTree()
     },
     handleResetAll() {
       this.checkedUsers=[];
       this.checkedUserIds=[];
       this.listQueryAll.condition.user_loginName.value = ''
       this.listQueryAll.condition.user_name.value = ''
       this.listQueryAll.condition.pt.value = '0'
       this.listQueryAll.rowBounds.offset = 0
       this.listQueryAll.rowBounds.limit = 10
       this.allTotal = 0
       this.serialNumberAll = 1
       this.getList()
     },
     handleResetOrg() {
       this.checkedOrgUsers=[];
       this.checkedOrgUserIds=[];
       this.listQueryDemo.condition.user_loginName.value = ''
       this.listQueryDemo.condition.user_name.value = ''
       this.listQueryDemo.condition.pt.value = '0'
       this.listQueryDemo.rowBounds.offset = 0
       this.listQueryDemo.rowBounds.limit = 10
       this.totalDemo = 0
       this.serialNumberOrg = 1
       this.selectUserByOrgId()
     },
     selectUserByOrgId() {
        userSelected(this.listQueryDemo).then(response => {
          this.userDataDemo = response.data.data.records
          this.totalDemo = response.data.data.count
        })
     }
  }
}
</script>

<style scoped>
.treeArea {
    max-height: 66vh;
    overflow-y: auto;
}
</style>
